.TH std::in_range 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::in_range \- std::in_range

.SH Synopsis
   Defined in header <utility>
   template< class R, class T >              \fI(since C++20)\fP
   constexpr bool in_range( T t ) noexcept;

   Returns true if the value of t is in the range of values that can be represented in
   R, that is, if t can be converted to R in a value-preserving manner.

   It is a compile-time error if either T or U is a non-integer type, a character type,
   or bool.

.SH Parameters

   t - value to test

.SH Return value

   true if the value of t is representable in R, false otherwise.

.SH Possible implementation

   template<class R, class T>
   constexpr bool in_range(T t) noexcept
   {
       return std::cmp_greater_equal(t, std::numeric_limits<R>::min()) &&
           std::cmp_less_equal(t, std::numeric_limits<R>::max());
   }

.SH Notes

   This function cannot be used with enums (including std::byte), char, char8_t,
   char16_t, char32_t, wchar_t and bool.

             Feature-test macro            Value    Std             Feature
   __cpp_lib_integer_comparison_functions 202002L (C++20) Integer comparison functions

.SH Example


// Run this code

 #include <iostream>
 #include <utility>

 int main()
 {
     std::cout << std::boolalpha;

     std::cout << std::in_range<std::size_t>(-1) << '\\n';
     std::cout << std::in_range<std::size_t>(42) << '\\n';
 }

.SH Output:

 false
 true

.SH See also

   ranges::min   returns the smaller of the given values
   (C++20)       (niebloid)
   ranges::max   returns the greater of the given values
   (C++20)       (niebloid)
   ranges::clamp clamps a value between a pair of boundary values
   (C++20)       (niebloid)
   lerp          linear interpolation function
   (C++20)       \fI(function)\fP
